home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4934 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  45 lines

  1. Path: ts2-022.jaxnet.com!user
  2. From: garyg@jax.jaxnet.com (Gary M. Greenberg)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What's your compiler's answer?
  5. Date: Sat, 10 Feb 1996 17:34:48 -0500
  6. Organization: Southeast Network Services, Inc.
  7. Message-ID: <garyg-1002961734480001@ts2-022.jaxnet.com>
  8. References: <1996Feb7.140945.28351@cs.rit.edu>
  9. NNTP-Posting-Host: ts2-022.jaxnet.com
  10.  
  11. In article <1996Feb7.140945.28351@cs.rit.edu>, kar@cs.rit.edu (Kenneth A
  12. Reek) wrote:
  13.  
  14. >          In preparing some materials for a course, I wrote the following
  15. >  program to illustrate that the order of expression evaluation is not
  16. >  determined completely by the precedence of the operators involved.  I
  17. >  ran it on every compiler I could find and, not surprisingly, got lots of
  18. >  different answers.
  19. [big chop]
  20. >  Here's the program (hold on to your hats):
  21. >  
  22. >          int main(){
  23. >                  int i = 10;
  24. >  
  25. >                  i = i-- - --i * ( i = -3 ) * i++ + ++i;
  26. >                  printf( "i = %d\n", i );
  27. >                  return 0;
  28. >          }
  29. >  
  30. >  Results found to date:
  31. [worthless stuff clipped]
  32.  
  33. Why not just teach your students that programs which invoke
  34. undefined behavior return results which they deserve. ;-)
  35.  
  36. >  Kenneth A. Reek                         kar@cs.rit.edu
  37.  
  38. C'ya,
  39.  
  40. gary    /* the Sorcerer's Apprentice */
  41.  
  42. "Why do we have to hide from the police, Daddy?"
  43. "Because we use vi, honey. They use emacs."
  44. "Unless we're on a Mac, then we use BBEdit 'cause `It Doesn't Suck!'"
  45.